//
//  ViewController.swift
//  ContentPriority
//
//  Created by NMXY on 2020/12/31.
//

import UIKit
//import SnapKit



class ViewController: UIViewController {
        
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.isHidden = false
        
        self.view.backgroundColor = UIColor.white
       
    }
    
    override func loadView() {
        super.loadView()
        
        
        // label 和 textfiled
        
        self.view.addSubview(self.nameLabel)
        self.view.addSubview(self.nameTextfield)
        
        self.view.addSubview(self.namePriorityLabel)
        self.view.addSubview(self.namePriorityTextfield)
        
        let layoutMarginsConstraint = self.view.layoutMarginsGuide
        NSLayoutConstraint.activate([
            self.nameLabel.leadingAnchor.constraint(equalTo: layoutMarginsConstraint.leadingAnchor),
            self.nameLabel.topAnchor.constraint(equalTo: layoutMarginsConstraint.topAnchor,constant:50),
            self.nameLabel.trailingAnchor.constraint(equalTo: self.nameTextfield.layoutMarginsGuide.leadingAnchor),
            
            self.nameTextfield.topAnchor.constraint(equalTo: layoutMarginsConstraint.topAnchor,constant:50),
            self.nameTextfield.leadingAnchor.constraint(equalTo: self.nameLabel.layoutMarginsGuide.trailingAnchor),
            self.nameTextfield.rightAnchor.constraint(equalTo: layoutMarginsConstraint.rightAnchor),
            
            self.namePriorityLabel.leadingAnchor.constraint(equalTo: layoutMarginsConstraint.leadingAnchor),
            self.namePriorityLabel.topAnchor.constraint(equalTo: layoutMarginsConstraint.topAnchor,constant: 90),
            self.namePriorityLabel.rightAnchor.constraint(equalTo: self.namePriorityTextfield.leftAnchor),
            
            self.namePriorityTextfield.leadingAnchor.constraint(equalTo: self.namePriorityLabel.trailingAnchor),
            self.namePriorityTextfield.topAnchor.constraint(equalTo: layoutMarginsConstraint.topAnchor,constant: 90),
            self.namePriorityTextfield.trailingAnchor.constraint(equalTo: layoutMarginsConstraint.trailingAnchor),
        
        ])
        
        //两个 label 一个正常展示，另一个换行
        
        self.view.addSubview(self.labelOne)
        self.view.addSubview(self.labelTwo)
        
        self.view.addSubview(self.labelPriorityOne)
        self.view.addSubview(self.labelPriorityTwo)
        
        NSLayoutConstraint.activate([
            self.labelOne.leadingAnchor.constraint(equalTo: layoutMarginsConstraint.leadingAnchor),
            self.labelOne.topAnchor.constraint(equalTo: layoutMarginsConstraint.topAnchor,constant: 150),
            self.labelOne.rightAnchor.constraint(equalTo: self.labelTwo.leftAnchor),
            
            self.labelTwo.leftAnchor.constraint(equalTo: self.labelOne.rightAnchor),
            self.labelTwo.topAnchor.constraint(equalTo: self.labelOne.topAnchor),
            self.labelTwo.trailingAnchor.constraint(equalTo: layoutMarginsConstraint.trailingAnchor),
            
            self.labelPriorityOne.leadingAnchor.constraint(equalTo: layoutMarginsConstraint.leadingAnchor),
            self.labelPriorityOne.topAnchor.constraint(equalTo: layoutMarginsConstraint.topAnchor,constant: 200),
            self.labelPriorityOne.rightAnchor.constraint(equalTo: self.labelPriorityTwo.leftAnchor),
            
            self.labelPriorityTwo.leftAnchor.constraint(equalTo: self.labelPriorityOne.rightAnchor),
            self.labelPriorityTwo.topAnchor.constraint(equalTo: self.labelPriorityOne.topAnchor),
            self.labelPriorityTwo.trailingAnchor.constraint(equalTo: layoutMarginsConstraint.trailingAnchor),
            
        ])
        
        // 两个 label 一个正常展示，另一个拉伸占满剩下的空间
        
        self.view.addSubview(labelThree)
        self.view.addSubview(labelFour)
        
        NSLayoutConstraint.activate([
            self.labelThree.topAnchor.constraint(equalTo: self.labelPriorityTwo.bottomAnchor,constant: 20),
            self.labelThree.leftAnchor.constraint(equalTo: layoutMarginsConstraint.leftAnchor),
            
            self.labelFour.topAnchor.constraint(equalTo:self.labelPriorityTwo.bottomAnchor,constant: 20),
            self.labelFour.leftAnchor.constraint(equalTo: self.labelThree.rightAnchor),
            self.labelFour.rightAnchor.constraint(equalTo: layoutMarginsConstraint.rightAnchor),
        ])
        
    }
     
    //MARK: label 和 textfiled
    private lazy var nameLabel: UILabel = {
        let tempLabel = UILabel()
        tempLabel.translatesAutoresizingMaskIntoConstraints = false
        tempLabel.text = "姓名"
        tempLabel.backgroundColor =  UIColor (displayP3Red: CGFloat(arc4random_uniform(256)) / 255.0, green: CGFloat(arc4random_uniform(256)) / 255.0, blue: CGFloat(arc4random_uniform(256)) / 255.0, alpha: 1)
        return tempLabel
    }()

    private lazy var nameTextfield:UITextField = {
        let textfield = UITextField ()
        textfield.placeholder = "请输入姓名"
        textfield.borderStyle = .line
        textfield.backgroundColor =  UIColor (displayP3Red: CGFloat(arc4random_uniform(256)) / 255.0, green: CGFloat(arc4random_uniform(256)) / 255.0, blue: CGFloat(arc4random_uniform(256)) / 255.0, alpha: 1)
        textfield.translatesAutoresizingMaskIntoConstraints = false
        return textfield
    }()
    
    
    private lazy var namePriorityLabel: UILabel = {
        let tempLabel = UILabel()
        tempLabel.translatesAutoresizingMaskIntoConstraints = false
        tempLabel.text = "姓名"
        tempLabel.backgroundColor =  UIColor (displayP3Red: CGFloat(arc4random_uniform(256)) / 255.0, green: CGFloat(arc4random_uniform(256)) / 255.0, blue: CGFloat(arc4random_uniform(256)) / 255.0, alpha: 1)
        tempLabel.setContentHuggingPriority(UILayoutPriority (251), for: .horizontal)
        return tempLabel
    }()

    private lazy var namePriorityTextfield:UITextField = {
        let textfield = UITextField ()
        textfield.placeholder = "请输入姓名"
        textfield.borderStyle = .line
        textfield.backgroundColor =  UIColor (displayP3Red: CGFloat(arc4random_uniform(256)) / 255.0, green: CGFloat(arc4random_uniform(256)) / 255.0, blue: CGFloat(arc4random_uniform(256)) / 255.0, alpha: 1)
        textfield.translatesAutoresizingMaskIntoConstraints = false
        return textfield
    }()
    


    //MARK: 两个 label 一个正常展示，另一个换行
    private lazy var labelOne: UILabel = {
        let tempLabel = UILabel()
        tempLabel.text = "labelOnelabel"
        tempLabel.translatesAutoresizingMaskIntoConstraints = false
        tempLabel.backgroundColor =  UIColor (displayP3Red: CGFloat(arc4random_uniform(256)) / 255.0, green: CGFloat(arc4random_uniform(256)) / 255.0, blue: CGFloat(arc4random_uniform(256)) / 255.0, alpha: 1)
        return tempLabel
    }()

    private lazy var labelTwo: UILabel = {
        let tempLabel = UILabel()
        tempLabel.text = "labelTwolabellabelTwolabellabelTwolabe"
        tempLabel.translatesAutoresizingMaskIntoConstraints = false
        tempLabel.numberOfLines = 0
        tempLabel.backgroundColor =  UIColor (displayP3Red: CGFloat(arc4random_uniform(256)) / 255.0, green: CGFloat(arc4random_uniform(256)) / 255.0, blue: CGFloat(arc4random_uniform(256)) / 255.0, alpha: 1)
        return tempLabel
    }()
    
    
    private lazy var labelPriorityOne: UILabel = {
        let tempLabel = UILabel()
        tempLabel.text = "labelOnelabel"
        tempLabel.translatesAutoresizingMaskIntoConstraints = false
        tempLabel.setContentCompressionResistancePriority(UILayoutPriority (999), for: .horizontal)
        tempLabel.backgroundColor =  UIColor (displayP3Red: CGFloat(arc4random_uniform(256)) / 255.0, green: CGFloat(arc4random_uniform(256)) / 255.0, blue: CGFloat(arc4random_uniform(256)) / 255.0, alpha: 1)
        return tempLabel
    }()

    private lazy var labelPriorityTwo: UILabel = {
        let tempLabel = UILabel()
        tempLabel.text = "labelTwolabellabelTwolabellabelTwolabe"
        tempLabel.translatesAutoresizingMaskIntoConstraints = false
        tempLabel.numberOfLines = 0
        tempLabel.backgroundColor =  UIColor (displayP3Red: CGFloat(arc4random_uniform(256)) / 255.0, green: CGFloat(arc4random_uniform(256)) / 255.0, blue: CGFloat(arc4random_uniform(256)) / 255.0, alpha: 1)
        return tempLabel
    }()
    
    //MARK: 两个 label 一个正常展示，另一个拉伸占满剩下的空间
    private lazy var labelThree: UILabel = {
        let tempLabel = UILabel()
        tempLabel.text = "labelThree"
        tempLabel.translatesAutoresizingMaskIntoConstraints = false
        tempLabel.backgroundColor =  UIColor (displayP3Red: CGFloat(arc4random_uniform(256)) / 255.0, green: CGFloat(arc4random_uniform(256)) / 255.0, blue: CGFloat(arc4random_uniform(256)) / 255.0, alpha: 1)
        return tempLabel
    }()

    private lazy var labelFour: UILabel = {
        let tempLabel = UILabel()
        tempLabel.text = "labelFour"
        tempLabel.textAlignment = .right
        tempLabel.translatesAutoresizingMaskIntoConstraints = false
        tempLabel.backgroundColor =  UIColor (displayP3Red: CGFloat(arc4random_uniform(256)) / 255.0, green: CGFloat(arc4random_uniform(256)) / 255.0, blue: CGFloat(arc4random_uniform(256)) / 255.0, alpha: 1)
        return tempLabel
    }()
    
    
    
    
    
}

